<?php
/**
 * 后台初始信息
 */
namespace app\api\controller;

class Index extends AuthBase
{
    private $name = 'controller.Index';

    /**
     * 后台初始信息
     * @return void
     */
    public function index()
    {
        try{
            $adminInfo =  \app\api\business\LoginBus::getUserInfo($this->userId);
            if($adminInfo){
                $data = ['adminInfo'=>[],'menus'=>[],'siteConfig'=>[],'terminal'=>[]];
                $adminInfo = json_decode($adminInfo,true);
                // 权限分组ID
                if($adminInfo['group_id']){
                    $adminGroup =  \app\api\business\AdminGroupBus::getConditionalQuery(['id'=>$adminInfo['group_id']]);
                    if($adminGroup){
                        if($adminGroup['rules'] =="*"){
                            $ids = \app\api\business\AdminRoleBus::getIdList();
                        }else{
                            $ids = explode(",",$adminGroup['rules']);
                        }
                        $role= \app\api\business\AdminRoleBus::getMultipleData($ids);
                        $roleResult =  \app\api\business\AdminRoleBus::getTreeData($role);
                        $data['menus'] = $roleResult;
                    }
                    if($adminInfo['group_id'] == 1){
                        $adminInfo['super'] = true;
                    }
                }
                $data['adminInfo'] = $adminInfo;
                $data['siteConfig'] = config("config.siteConfig");
                $data['terminal'] = ['installServicePort'=>8000,'npmPackageManager'=>'npm'];
                if($data){
                    return returnResult(config("config.code.success"),config("config.describe.success"),$data);
                }else{
                    return returnResult(config("config.code.error"),config("config.describe.error"));
                }
            }else{
                return returnResult(config("config.code.error"),"请重新登录!");
            }
        }catch (\Exception $e){
            exception($e,self::$name.'.index');
        }
    }

    /**
     * 控制台信息
     * @return void
     */
    public function dashboard()
    {
        try{
            $data['remark'] = "开源等于互助；开源需要大家一起来支持，支持的方式有很多种，比如使用、推荐、写教程、保护生态、贡献代码、回答问题、分享经验、打赏赞助等；欢迎您加入我们！";
            return returnResult(config("config.code.success"),config("config.describe.success"),$data);
        }catch (\Exception $e){
            exception($e,self::$name.'.dashboard');
        }
    }
}